package com.softbank.bsdiff;

import android.app.DownloadManager;
import android.net.Uri;

import java.io.File;

public class DownloadUtils {

    public static long startDownload(String title, String desc, String downLoadUrl, File outputFile, DownloadManager downloadManager) {
        DownloadManager.Request request = new DownloadManager.Request(Uri.parse(downLoadUrl));
        //设置漫游条件下是否可以下载
        request.setAllowedOverRoaming(false);
        //在通知栏中显示，默认就是显示的
        request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE);
        //设置通知标题
        request.setTitle(title);
        //设置通知标题message
        request.setDescription(desc);
        request.setVisibleInDownloadsUi(true);
        //设置文件存放路径
        request.setDestinationUri(Uri.fromFile(outputFile));
//                pathstr = file.getAbsolutePath();
        //将下载请求加入下载队列，加入下载队列后会给该任务返回一个long型的id，通过该id可以取消任务，重启任务、获取下载的文件等等
        if (downloadManager != null) {
            return downloadManager.enqueue(request);
        } else {
            return 0;
        }
    }
}
